-
Notifications
You must be signed in to change notification settings - Fork 477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow overriding stream list implementation #612
Conversation
to make it work with the generalized interface, instead of removing only the matching streams and then merging both lists, we remove & add every stream. the old stream is then deallocated and replaced by the newly produced one
custom implementations need to have it available
removes code duplication as well
@fluffy @bifurcation could you take a look at this, please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I think this is a better approach, did a quick review but will try to look in more detail in the next days.
With this API there is the assumption that inserting can never fail, maybe it should return a status.
Yes, inserting a duplicate key is defined as UB. This is because in the current code, when inserting a stream we don't check that another one with the same SSRC already exists. Since we make this assumption, in order to keep the current performance it's necessary to allow implementations to assume that as well... otherwise the default implementation for This was the reasoning but of course it's easy to change if you prefer a checked insertion, or an advisory returned status |
I was more thinking if it failed due to some capacity issues or something similar in what ever list implementation was used. If the item did not actually get put in to a list it would cause a memory leak. |
I see, that makes sense. I've amended |
So first, I think refactoring along theses lines sounds like a good idea and makes sense. I would want to be very careful this did not break things and I have not carefully reviewed the code but I do like the basic idea. |
I think it we had this, it would make it much easier to also put the optimized version from 508 into the main repo and not just have it in a downstream. |
Agree. Most of the changes just extract code into the functions, but there are 2 places (feac4ce and 6653a86) where I've had to change behavior a bit to generalize, which need thorough review. |
@mildsunrise Hi! I've tried to implement a custom |
@dsdolzhenko I will try the same, I am not sure that this "feature" will just work using the build files provided with libsrtp out of the box, we would have to think if that is what we would want to support. I have the feeling that to start with this feature is more for custom builds of libsrtp where teams have their own build files for libsrtp. |
This is the intent, yes. As mentioned this is an internal API and thus doesn't have the stability guarantees that public APIs have, it's targeted towards projects that do custom builds. We can always support more use cases later, but in any case I'd personally leave the changes sitting there for some time before stabilizing. |
Ok, got it. Thank you for the clarifications and for the MR ;) |
Hi @mildsunrise, it has been awhile but I am now trying to get this in. I have made some local api changes, my suggestion is
and have changed the internal implementation to be a double linked list. I am not sure how you have replaced the api in your code so I am not sure if this will break anything for you. |
Beside some small API rename the main difference is that the list implementation is not responsible for deallocating streams. Calling srtp_stream_list_dealloc() on a list that is not empty results in an error. This also changes the default implementation to be a double linked list making removing items faster.
Commit 914cb55 in #632 contains some small proposed changes to this PR. If they look ok in general then will merge them here for complete review. @mildsunrise do you think it is still compatible with want you initially wanted? |
I agree that this seems like a good approach. Happy to do a detailed review once we make a decision on #632. Also agree with @fluffy that it would be good to fold in #508 after we merge this. Together with the fact that people seem to want to do other proprietary implementations, maybe we want three states for the implementation:
This seems analogous to the crypto library selection, so probably good to do this switching in the same way -- put these in separate files and switch among them using the build system. |
if I'm not missing anything, changes proposed by @pabuhler in #632 are:
I'm happy with the changes and yes, this is compatible with what we had. the only thing I want to point out is the last change, where the stream parameter is effectively an iterator for the internal (intrusive) implementation, but not other implementations. so your code shouldn't expect O(1) removes; if that may be needed, we should extend the API to expose iterators I think. if not the case then I'm 👍 on merging #632 and closing this |
Thanks @mildsunrise & @bifurcation , @mildsunrise you summary is correct. |
This does it in a cross platform manor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partial review here, just covering the high-level design.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, with the discussion from the first review, this looks about right. Just a bunch of minor things to fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the work on this @mildsunrise and @pabuhler. Looks good to me with the latest changes.
Thank you everyone :) @murillo128 I'll integrate this into the media server when I find a spot |
Hello! This PR proposes to refactor the logic managing the
stream_list
(which is currently an intrusive singly linked list) into its own functions:These functions are then gated by a define, so that downstreams can remove the default linked list implementation and replace it with one suited to their needs.
More precisely, the linked list is generalized to an opaque API (
stream_list_priv.h
) with only the semantics I thought we'd need (retrieval, insertion, removal, and iteration that allows removing the currently iterating element) documented. It's still an internal API, we're not asking for stability on these semantics or signatures; the only requirement is thatstream_list
must be updated only through this API, and that this file is kept up to date with any semantics the rest of the code relies on.It's an alternative to #508 that we believe should be more flexible for everybody and hopefully introduce less maintenance burden on your side, as well as avoid changing the current behavior. What are your thoughts on it?
/cc @murillo128